package cn.springcloud.fix.samples.controller;

import cn.hutool.core.util.RandomUtil;
import cn.springcloud.fix.common.core.utils.StringUtil;
import cn.springcloud.fix.samples.config.RabbitConfig;
import cn.springcloud.fix.samples.mq.MessageHelper;
import cn.springcloud.fix.samples.vo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/mq")
public class MqTestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/sendMsg")
    public String sendMsg() {
        String msgId = StringUtil.UUID32();
        User user = new User(1, "yj", 30);
        CorrelationData correlationData = new CorrelationData(msgId);
        rabbitTemplate.convertAndSend(RabbitConfig.LOGIN_LOG_EXCHANGE_NAME, RabbitConfig.LOGIN_LOG_ROUTING_KEY_NAME, MessageHelper.objToMsg(user), correlationData);
        return "success";
    }
}
